<template>
  <div>
    <div class="layout">
      <div>
        <BackNav left-text="返回" left-arrow title="我的收藏"></BackNav>
      </div>
      <div class="top"></div>
      <div class="wrapper">
        <div class="main" v-if="show">
          <div class="like-item" v-for="(item, index) in likelist" :key="index">
            <div class="img-box">
              <img :src="item.smallImg" class="auto-img" alt="" />
            </div>
            <div class="zename">
              <div class="zh-name">{{ item.name }}</div>
              <div class="en-name">{{ item.ennname }}</div>
            </div>
            <div class="footer">
              <div class="price">&yen;{{item.price}}</div>
              <div class="icon" @click="del(item.pid)">
                <van-icon
                  name="delete-o"
                  size="16"
                  class="ic"
                />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import BackNav from "../components/BackNav";
export default {
  components: {
    BackNav,
  },
  created() {
    this.alllike();
  },
  data() {
    return {
      likelist: [],
      show: false,
    };
  },
  methods: {
    // 查询收藏
    alllike() {
      this.axios({
        url: "/findAllLike",
        method: "get",
      })
        .then((res) => {
          
          if (res.data.code == 2000) {
            if (res.data.result.length != 0) {
              this.show = true;
              this.likelist = res.data.result;
            } else {
              this.likelist=[]
              this.show = false;
            }
          }
        })
        .catch((err) => {
          
        });
    },
    // 删除收藏
    del(pid) {
      
      this.axios({
        url: "/notlike",
        method: "post",
        data: {
          pid,
        },
      })
        .then((res) => {
          
          if(res.data.code==900){
            this.alllike();
          }
        })
        .catch((err) => {
          
        });
    },
  },
};
</script>
<style lang="less" scoped>
.layout {
  background: #f0f0f0;
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  .top {
    height: 100px;
    background: #0c43ba;
  }
  .wrapper {
    width: 90%;
    background: #fff;
    position: relative;
    top: -20px;
    border-radius: 10px;
    margin: 0 auto;
    .main {
      display: flex;
      flex-wrap: wrap;
      padding: 5px;
      .like-item {
        padding: 5px;
        .img-box {
          width: 95px;
          height: 95px;
          background: #f0f0f0;
        }
        .zename {
          line-height: 1.5;
          margin-top: 5px;
          margin-bottom: 10px;
          .zh-name {
            color: #7c868f;
            font-size: 14px;
          }
          .en-name {
            color: #aa9cb4;
            font-size: 14px;
          }
        }
        .footer {
          display: flex;
          .price {
            color: #0c43ba;
            font-weight: bold;
            font-size: 14px;
          }
          .icon {
            margin-left: auto;
            .ic {
              vertical-align: middle;
            }
          }
        }
      }
    }
  }
}
</style>